import { LogLevel, SystemType, LogAppender } from '../../../constants/log';
/**
 * 验证查询表单字段是否合法
 * @param {object} form 查询表单
 */
export function validateSearchForm(form) {
  if (!form.start) return '请选择查询开始时间';
  if (!form.end) return '请选择查询结束时间';

  return null;
}

/**生成系统日志级别下拉列表可选数据*/
export function generateLevelSelectorData() {
  const result = [];
  Object.values(LogLevel).forEach(level => {
    result.push({ value: level, label: getLevelDisplay(level) });
  });

  return result;
}

/**
 * 获取日志级别显示内容
 * @param {string} level 日志级别
 */
export function getLevelDisplay(level) {
  switch (level) {
    case LogLevel.Trace:
      return '追溯';
    case LogLevel.Debug:
      return '调试';
    case LogLevel.Info:
      return '信息';
    case LogLevel.Warn:
      return '警告';
    case LogLevel.Error:
      return '错误';
    case LogLevel.Fatal:
      return '严重错误';
    default:
      return '未知级别';
  }
}

/**
 * 获取日志级别显示颜色
 * @param {string} level 日志级别
 */
export function getLevelColor(level) {
  switch (level) {
    case LogLevel.Trace:
      return '#BBBBBB';
    case LogLevel.Debug:
      return '#10aeff';
    case LogLevel.Info:
      return '#07c160';
    case LogLevel.Warn:
      return '#ffc300';
    case LogLevel.Error:
      return '#fa5151';
    case LogLevel.Fatal:
      return '#fa5151';
    default:
      return '#FFFFFF';
  }
}
